<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box1 {
            width: 500px;
            height: 500px;
            background-color: pink;
            margin: 0 auto;
        }
        #box2 {
            width: 300px;
            height: 300px;
            background-color: skyblue;
        }
        #box3 {
            display: block;
            width: 100px;
            height: 100px;
            background-color: green;
        }
    </style>
</head>
<body>
    <div id="box1">box1
        <div id="box2">box2
            <a id="box3" href="https://www.baidu.com">box3</a>
        </div>
    </div>
    <script>
        // 获取元素
        var box1 = document.getElementById("box1")
        var box2 = document.getElementById("box2")
        var box3 = document.getElementById("box3")
        // 阻止默认行为
        // box3.addEventListener("click", function (e) {
        //     // 阻止默认行为
        //     e.preventDefault();
        //     console.log("box3");
        // });
        // ie阻止默认行为
        // box3.attachEvent("onclick", function (e) {
        //     // 阻止默认行为
        //     e.returnValue = false;
        //     console.log("box3");
        // });
        // dom0阻止默认行为
        box3.onclick = function () {
            console.log("box3");
            return false;
        }
    </script>
</body>
</html>